package com.geek.gkpush.framework.retry.model;

import com.geek.gkpush.framework.retry.enums.ExecStatusEnum;
import com.geek.gkpush.framework.retry.enums.RetryResultEnum;
import com.geek.gkpush.util.str.StringCutUtils;
import lombok.Getter;
import lombok.Setter;
import lombok.ToString;

import java.io.Serializable;

/**
 * <h1>重试消息结果对象。</h1><br/>
 *
 * <h1><br/><a href="https://u.geekbang.org/subject/arch3/100614201">Java 业务架构实战营：https://u.geekbang.org/subject/arch3/100614201</a></h1><br/><h1><a href="https://gitee.com/ylimhhmily/BizArchPracticeCamp">Java 业务架构实战营代码地址：https://gitee.com/ylimhhmily/BizArchPracticeCamp</a></h1><br/><h1><a href="https://u.geekbang.org/subject/java4th/1001148?source=app_share">高级 Java 工程体系课 2023 版：https://u.geekbang.org/subject/java4th/1001148?source=app_share</a></h1><br/><h1><a href="https://time.geekbang.org/column/intro/100312101?tab=catalog">Dubbo 源码剖析与实战：https://time.geekbang.org/column/intro/100312101?tab=catalog</a></h1>
 *
 * @author hmilyylimh
 * ^_^
 * @version 0.0.1
 * ^_^
 * @date 2023/10/3 09:49
 */
@Getter
@Setter
@ToString(callSuper = true)
public class RetryResult implements Serializable {

    private static final long serialVersionUID = -8429619948054164198L;

    /** <h2>重试失败的枚举类型</h2> **/
    private RetryResultEnum retryResultEnum;

    /** <h2>推送状态.INIT-初始;SUCC-成功;</h2> **/
    private String srcExecStatus = ExecStatusEnum.ING.getCode();

    /** <h2>异常堆栈信息</h2> **/
    private String exceptionMsg;

    /**
     * <h2>根据成功对象。</h2>
     *
     * @return: com.geek.gkpush.framework.retry.model.RetryResult
     */
    public static RetryResult createSucc() {
        RetryResult result = new RetryResult();
        result.setRetryResultEnum(RetryResultEnum.SUCC);
        return result;
    }

    /**
     * <h2>根据失败对象。</h2>
     *
     * @param: stackTrace
     * @return: com.geek.gkpush.framework.retry.model.RetryResult
     */
    public static RetryResult createFail(String stackTrace) {
        RetryResult result = new RetryResult();
        result.setRetryResultEnum(RetryResultEnum.FAIL);
        result.setExceptionMsg(StringCutUtils.cut(stackTrace, 1800));
        return result;
    }

    /**
     * <h2>根据枚举值创建对象。</h2>
     *
     * @param: retryResultEnum
     * @param: srcExecStatus
     * @return: com.geek.gkpush.framework.retry.model.RetryResult
     */
    public static RetryResult create(RetryResultEnum retryResultEnum, String srcExecStatus) {
        RetryResult result = new RetryResult();
        result.setRetryResultEnum(retryResultEnum);
        result.setSrcExecStatus(srcExecStatus);
        return result;
    }

    /**
     * <h2>根据枚举值创建对象。</h2>
     *
     * @param: stackTrace
     * @return: com.geek.gkpush.framework.retry.model.RetryResult
     */
    public static RetryResult createException(String stackTrace) {
        RetryResult result = new RetryResult();
        result.setRetryResultEnum(RetryResultEnum.EXCEPTION);
        result.setExceptionMsg(StringCutUtils.cut(stackTrace, 1800));
        return result;
    }
}